function [ data ] = checkBounds(data)
load_settings;
% fix bounds for single image

fn = strcat(image_root, sprintf('%08d', data.cam_id), '/', data.filename);
img = imread(fn);
[iheight iwidth irgb] = size(img);

if isempty(data.ppl_rects)
    disp('checkBounds: No positive examples to fix bounds for');
else
    for ix = 1:size(data.ppl_rects, 1)
        cur_rect = data.ppl_rects(ix,:);
        x = cur_rect(1);
        y = cur_rect(2);
        xx = cur_rect(1)+cur_rect(3);
        yy = cur_rect(2)+cur_rect(4);
        
        %check if rectangle is completely outside of image, if only
        %partially then crop to edges
        if x > iwidth; % x is outside width
            omit = 1;
        end
        if y > iheight;
            omit = 1;
        end
        if x <= 0; % crop to left edge
            cur_rect(1) = 1;
        end
        if y <= 0; % crop to top edge
            cur_rect(2) = 1;
        end
        if xx > iwidth; % crop to right
            cur_rect(3) = iwidth - x;
        end
        if yy > iheight; % crop to bottom
            cur_rect(4) = iheight - y;
        end
        data.ppl_rects(ix,:) = cur_rect;
    end
end
%%
if isempty(data.bg_rects)
    disp('checkBounds: No negative examples to fix bounds for');
else
    for ix = 1:size(data.bg_rects, 1)
        cur_rect = data.bg_rects(ix,:);
        x = cur_rect(1);
        y = cur_rect(2);
        xx = cur_rect(1)+cur_rect(3);
        yy = cur_rect(2)+cur_rect(4);
        
        %check if rectangle is completely outside of image, if only
        %partially then crop to edges
        if x > iwidth; % x is outside width
            omit = 1;
        end
        if y > iheight;
            omit = 1;
        end
        if x <= 0; % crop to left edge
            cur_rect(1) = 1;
        end
        if y <= 0; % crop to top edge
            cur_rect(2) = 1;
        end
        if xx > iwidth; % crop to right
            cur_rect(3) = iwidth - x;
        end
        if yy > iheight; % crop to bottom
            cur_rect(4) = iheight - y;
        end
        data.bg_rects(ix,:) = cur_rect;
    end
end


end